all files / datePicker/ dayButton.vue

25% Statements 3/12
0% Branches 0/10
0% Functions 0/7
20% Lines 2/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71  1×                                                                                                                                          
 
import {isPc} from '../utils'
export default {
  props: {
    selected: {
      type: Boolean,
      default: false
    },
    date: {
      type: Date
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      hover: false
    }
  },
  computed: {
    isNow () {
      const now = new Date()
      return this.date && this.date.getYear() === now.getYear() && this.date.getMonth() === now.getMonth() && this.date.getDate() === now.getDate()
    },
    dayButtonClass () {
      return {
        selected: this.selected,
        hover: this.hover,
        'mu-day-button': true,
        disabled: this.disabled,
        now: this.isNow
      }
    }
  },
  methods: {
    handleHover () {
      if (isPc() && !this.disabled) this.hover = true
    },
    handleHoverExit () {
      this.hover = false
    },
    handleClick (event) {
      this.$emit('click', event)
    }
  },
  render (h) {
    return this.date ? h('button', {
      class: this.dayButtonClass,
      on: {
        mouseenter: this.handleHover,
        mouseleave: this.handleHoverExit,
        click: this.handleClick
      },
      domProps: {
        disabled: this.disabled
      }
    }, [
      h('div', {class: 'mu-day-button-bg'}),
      h('span', {
        class: 'mu-day-button-text',
        domProps: {
          innerHTML: this.date.getDate()
        }
      })
    ]) : h('span', {class: 'mu-day-empty'})
  }
}